import 'package:flutter/material.dart';
import 'package:star_author/config/base_configuration.dart';

class MarkWidget extends StatelessWidget {
  int number;
  Color numberColor;
  double numberFontSize;
  late EdgeInsets? padding;
  Border? border;
  Widget child;
  double? left, top, right, bottom;

  MarkWidget({
    Key? key,
    required this.child,
    required this.number,
    this.numberFontSize = 11,
    this.left,
    this.top = 0.04,
    this.right = 0.0,
    this.bottom,
    this.numberColor = ColorConf.normal,
    this.padding,
    this.border,
  }) {
    this.padding = padding ?? EdgeInsets.fromLTRB(4.0, 2.0, 4.0, 2.0);
    this.border = border;
  }

  @override
  Widget build(BuildContext ctx) {
    return Stack(
      alignment: Alignment.center,
      clipBehavior: Clip.none,
      children: [
        child,
        number > 0
            ? Positioned(
                right: right,
                top: top,
                left: left,
                bottom: bottom,
                child: Container(
                  padding: padding,
                  alignment: Alignment.centerRight,
                  decoration: BoxDecoration(
                    border: border,
                    borderRadius: BorderRadius.circular(50.0),
                    color: number > 0 ? ColorConf.red : Color(0x00),
                  ),
                  child: Text(
                    number < 1000.0 ? number.toString() : '999+',
                    style: TextStyle(
                      fontSize: numberFontSize,
                      height: 1,
                      color: numberColor,
                    ),
                    textAlign: TextAlign.end,
                  ),
                ),
              )
            : SizedBox.shrink(),
      ],
    );
  }
}

class RedMarkWidget extends StatelessWidget {
  bool needRedMark;
  late EdgeInsets? padding;
  Border? border;
  Widget child;
  double? left, top, right, bottom;

  RedMarkWidget({
    Key? key,
    required this.child,
    this.left,
    this.top = 0.04,
    this.right = 0.0,
    this.bottom,
    this.padding,
    this.border,
    this.needRedMark: false,
  }) {
    this.padding = padding ?? EdgeInsets.fromLTRB(4.0, 2.0, 4.0, 2.0);
    this.border = border;
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.center,
      clipBehavior: Clip.none,
      children: [
        child,
        if (needRedMark)
          Positioned(
            right: right,
            top: top,
            left: left,
            bottom: bottom,
            child: Container(
              padding: padding,
              alignment: Alignment.centerRight,
              decoration: BoxDecoration(
                border: border,
                borderRadius: BorderRadius.circular(50.0),
                color: ColorConf.red,
              ),
            ),
          ),
      ],
    );
  }
}
